clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

********************************************************************************************************
********************************** Table S9: Robustness test – Alternative measures of temperature
********************************************************************************************************

// alternative temperature measures
use "${date}/_data/temperature.dta"

gen log_temp = ln(temp)
gen temp_fdegree = (temp*9/5) + 32

bysort geo_code2_new (year): egen temp_sd = sd(temp)
gen temp_deviation = (temp - temp_longmean)/temp_sd
gen temp_shock = temp_deviation>=2 | temp_deviation<=-2

tempfile temperature_robustness
save `temperature_robustness'

use "${date}/_data/spid_for_analysis_v2.dta", clear

sort geo_code2_new year
	merge m:1 geo_code2_new year using `temperature_robustness'
	drop if _merge==2
	drop _merge
	
egen bin28days = rowtotal(bin4_9 bin4_10)

local controls ln_GDPppp Unempilo agri manuf popgr 

// Poverty
estimates clear
qui reghdfe poor215 log_temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m1
qui reghdfe poor215 temp_fdegree rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m2
qui reghdfe poor215 bin28days rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m3
qui reghdfe poor215 temp rainfall_sum humid `controls' if temp<=28, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m4
qui reghdfe poor215 temp_shock rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m5

local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) ///
	collabels(,none) keep(log_temp temp_fdegree bin28days temp temp_shock)	
	
esttab m*, `opts'
esttab m* using "${date}/_tables/_tab_s9a.csv", replace `opts'

	
// Inequality	
estimates clear
qui reghdfe gini log_temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m1
qui reghdfe gini temp_fdegree rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m2
qui reghdfe gini bin28days rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m3
qui reghdfe gini temp rainfall_sum humid `controls' if temp<=28, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m4
qui reghdfe gini temp_shock rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m5

local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) ///
	collabels(,none) keep(log_temp temp_fdegree bin28days temp temp_shock)	
	
esttab m*, `opts'
esttab m* using "${date}/_tables/_tab_s9b.csv", replace `opts'
